package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.LocationInfo;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.util.Utils;

/**
 * @author ln
 * @date 2020/3/27
 * description：地图列表适配器
 */
public class MapLoactionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private ItemClickListener mItemClickListener;
    private List<LocationInfo> list;
    private Context context;

    public void setList(List<LocationInfo> list) {
        notifyDataSetChanged();
        this.list = list;
    }

    public MapLoactionAdapter(List<LocationInfo> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_map_down_location, parent, false);
        MyViewHolder myHolder = new MyViewHolder(inflate);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        if (position==0){
            ((MyViewHolder) holder).ivMapDownLocation.setVisibility(View.VISIBLE);
        }else {
            ((MyViewHolder) holder).ivMapDownLocation.setVisibility(View.INVISIBLE);
        }
            ((MyViewHolder) holder).tvMapDownLocationTitle.setText(list.get(position).getTitle());
            ((MyViewHolder) holder).tvMapDownLocationContent.setText(list.get(position).getAddress());
            ((MyViewHolder) holder).rlMapDownLocation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (Utils.isFastClick()) {
                        mItemClickListener.onItemClick(position);
                    }
                }
            });

    }

    @Override
    public int getItemCount() {
            return list.size();
    }

     class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView tvMapDownLocationTitle;
        private TextView tvMapDownLocationContent;
        private RelativeLayout rlMapDownLocation;
        private ImageView ivMapDownLocation;
        public MyViewHolder(View itemView) {
            super(itemView);
            tvMapDownLocationTitle = itemView.findViewById(R.id.tv_map_down_location_title);
            tvMapDownLocationContent = itemView.findViewById(R.id.tv_map_down_location_content);
            rlMapDownLocation = itemView.findViewById(R.id.rl_map_down_location);
            ivMapDownLocation = itemView.findViewById(R.id.iv_map_down_location);
        }
    }



    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}
